﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;

namespace Dac.Code
{
    public class BasePage : Page
    {
        public string JsCodeToRunOnReady { get; set; }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            JsCodeToRunOnReady = "";
        }

        public bool IsAuthentificated
        {
            get { return System.Web.HttpContext.Current.User.Identity.IsAuthenticated; }
        }

        public string BasePath
        {
            get { return ResolveClientUrl("~"); }
        }
        
        public bool IsAdmin
        {
            get
            {
                if (IsAuthentificated)
                    return Roles.IsUserInRole("admin");

                return false;
            }

        }
        
        protected string GetIPAddress()
        {

            return Request.UserHostAddress;
        }

        protected void AlertAndClear(string message)
        {
            Response.Clear();
            Response.Write(string.Format("<script type=\"text/javascript\">alert('{0}');</script>", message));
            Response.End();
        }

        public bool IsIE()
        {
            //return !((Request.Browser.Browser.ToLower() == "chrome") || (Request.Browser.Browser.ToLower() == "firefox"));
            return ((Request.Browser.Browser.ToLower() == "ie") || (Request.Browser.Browser.ToLower() == "mozilla"));
        }

    }
}